<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<%@include file="/common/head.jsp" %>
<%--<c:set var="module" value="news"/>--%>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                    	<form role="form" class="form-inline" id="query-form" method="post" action="${ctx }/admin/news/list" >
                    		<!-- 查询开始 -->
                          <div class="form-group">
                                <label for="query-name" class="sr-only2">部门名</label>
                                	<input type="text" id="query-name" name="name" value="${query.name }" class="form-control input-sm">

                            </div>
                            <div class="form-group">
                                <label for="query-serialNum" class="sr-only2">编号</label>
                                	<input type="text" id="query-serialNum" name="serialNum" value="${query.serialNum }" class="form-control input-sm">
                                
                            </div>
                            <div class="form-group">
                                <label for="query-status" class="sr-only2">状态</label>
                                	<input type="text" id="query-status" name="status" value="${query.status }" class="form-control input-sm">
                                
                            </div>
                            <div class="form-group">
                                <label for="query-title" class="sr-only2">标题</label>
                                	<input type="text" id="query-title" name="title" value="${query.title }" class="form-control input-sm">
                                
                            </div>
                            <div class="form-group">
                            	<button class="btn btn-primary btn-sm" type="submit"><i class="fa fa-search"></i>&nbsp;查询</button>
                            </div>
                            <!-- 查询结束 -->
                        </form>
                    
						<div>
							<p>
								<%--<sec:authorize ifAnyGranted="example.delete">

								</sec:authorize>--%>

									<%--<sec:authorize ifAnyGranted="roleMenu">--%>
							<button type="button" class="btn btn-sm btn-outline btn-primary" onclick="add()"><i class="fa fa-plus"></i> 新增</button>
							<button type="button" class="btn btn-sm btn-outline btn-info " onclick="edit()"><i class="fa fa-paste"></i> 详情</button>
		                        <button type="button" class="btn btn-sm btn-outline btn-danger" onclick="del();">删除</button>
<%--</sec:authorize>--%>
		                        <button type="button" class="btn btn-sm btn-outline btn-info " onclick="reOpen()"><i class="fa fa-refresh"></i> 刷新</button>
		                    </p>
						</div>
						<table id="table" data-toggle="table" data-striped="true" data-click-to-select="true" data-mobile-responsive="true">
                                    <thead>
                                        <tr>
                                            <th data-field="_state" data-checkbox="true"></th>
                                            <th data-field="id" data-visible="false">ID</th>
                                            <th data-field="name">部门名</th>
                                            <th data-field="serialNum">编号</th>
                                            <th data-field="status">状态</th>
                                            <th data-field="title">标题</th>
                                            <th data-field="summary">概要</th>
                                            <%--<th data-field="thumb">缩略图</th>--%>
                                            <th data-field="content">新闻文本内容</th>
                                            <th data-field="creator">创建人</th>
                                            <th data-field="createTime">创建时间</th>
                                            <th data-field="updator">更新人</th>
                                            <th data-field="updateTime">更新时间</th>
                                        </tr>
                                    </thead>
							<tbody>
								<c:forEach items="${list }" var="n" varStatus="idx">
								<tr data-index="${idx.index }" data-id="${n.id }">
									<td class="bs-checkbox">
										<input data-index="0" name="btSelectItem" type="checkbox">
									</td>
									<td style="">${n.id }</td>
									<td style="">${n.name }</td>
									<td style="">${n.serialNum }</td>
									<td>
										<c:if test="${'状态1' eq enum:list('NewsStatus', n.status) }">已上架</c:if>
										<c:if test="${'状态2' eq enum:list('NewsStatus', n.status) }">未上架</c:if>
									</td>
									<%--<td>${enum:list('NewsStatus', n.status)}</td>--%>
									<td style="">${n.title }</td>
									<td style="">${n.summary }</td>
									<%--<td style="">${n.thumb }</td>--%>
									<td style="">${n.content }</td>
									<td style="">${n.creator.id}</td>
									<td style="">
										<fmt:formatDate value="${n.createTime }" pattern="yyyy-MM-dd"/>
									</td>
									<td style="">${n.updator.id}</td>
									<td style="">
										<fmt:formatDate value="${n.updateTime }" pattern="yyyy-MM-dd"/>
									</td>
								</tr>
								</c:forEach>
							</tbody>
						</table>
                   
						<%@include file="/common/page.jsp" %>

					</div>
                </div>
            </div>
        </div>
    </div>

<%@include file="/common/foot.jsp" %>
<script>
function add() {
    layer.open({
        type: 2,
        skin: 'layui-layer-rim', //加上边框
        area: [layer_default_width, layer_default_height], //宽高
        content: "${ctx}/admin/news/detail",
        btn: ['确定', '取消'],
        yes: function(index, layero){ //或者使用btn1
            var detailForm = layer.getChildFrame('form', index);
            console.log(detailForm);
            var name = $('#name', detailForm).val();
            if(!!!name){alert('请输入部门名.');return false;}
            var status = $('#status', detailForm).val();
            if(!!!status){alert('请输入状态.');return false;}
            var summary = $('#summary', detailForm).val();
            if(!!!summary){alert('请输入概要.');return false;}
            var content = $('#content', detailForm).val();
            if(!!!content){alert('请输入内容.');return false;}
            var createTime = $('#createTime', detailForm).val();
            if(!!!createTime){alert('请选择创建时间.');return false;}

            var updateTime = $('#updateTime', detailForm).val();
            if(!!!updateTime){alert('请选择更新时间.');return false;}
           /* var email = $('#email', detailForm).val();
            if(!!!email){alert('请输入邮箱.');return false;}
            var emailReg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            if(!emailReg.test(email)) {
                alert('请输入正确的邮箱.');
                return false;
            }*/

           detailForm.ajaxSubmit({
                success: function(data) {
                    if (isSuccess(data)) {
                        layer.close(index);
                        reload();
                    } else {
                    }
                }
            });
        }, cancel: function(index){ //或者使用btn2
            //按钮【按钮二】的回调
        }
    });
   /* k.layer.add("${ctx}/admin/news/detail");*/
}

function edit() {
    var selections = $('#table').bootstrapTable('getAllSelections');
	if (selections.length != 1) {
		error2(k.msg.requireOne);
		return;
	}
	var id = selections[0].id;
	k.layer.edit("${ctx}/admin/news/detail?id=" + id);
}
var page = "${page.page}";
function reload() {
	page_submit(page);
}
/*function del() {
	k.layer.del("${ctx}/admin/news/delete");	
}*/
function del() {
    var selections = $('#table').bootstrapTable('getAllSelections');
    if (selections.length < 1) {
        error('请选择要删除的记录');
        return;
    }
    layer.confirm('确认要删除吗?', {icon: 3, title:'提示'}, function(index){
        var ids = new Array();
        for (var i = 0; i < selections.length; i++) {
            ids.push(selections[i].id);
        }
        $.ajax({
            url: "${ctx}/admin/news/delete",
            data: {
                ids: ids.join(',')
            },
            success: function(data) {
                if (isSuccess(data)) {
                    layer.close(index);
                    reload();
                }
            }
        });
    });



    k.layer.del("${ctx}/admin/news/detail?id=" + id);

}
paging('pagination', ${page.totalPages}, ${page.page});

</script>
</body>
</html>